package cn.janyd.jmall.userweb.manager.user;

import cn.janyd.common.core.vo.CommonResult;
import cn.janyd.jmall.user.rpc.user.UserRpcService;
import cn.janyd.jmall.user.rpc.user.dto.UserRespDTO;
import cn.janyd.jmall.userweb.controller.user.vo.UserRespVo;
import cn.janyd.jmall.userweb.converter.UserConverter;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * @author janyd
 * @since 2020/8/11 22:03
 */
@Service
public class UserManager {

    @DubboReference(version = "${jmall.dubbo.versions.UserRpcService}")
    private UserRpcService userRpcService;

    /**
     * 获取用户信息
     *
     * @param userId 用户ID
     * @return 用户信息
     */
    public UserRespVo getUser(Integer userId) {
        final CommonResult<UserRespDTO> userResult = userRpcService.getUser(userId);
        userResult.checkError();
        return UserConverter.INSTANCE.convert(userResult.getData());
    }
}
